package com.sys.platform.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sys.platform.common.web.controller.BaseController;
import com.sys.platform.common.web.domain.AjaxResult;
import com.sys.platform.common.web.page.TableDataInfo;
import com.sys.platform.entity.DossierDeviceWarning;
import com.sys.platform.entity.request.dossierDeviceWarning.DossierDeviceWarningAddDTO;
import com.sys.platform.entity.request.dossierDeviceWarning.DossierDeviceWarningInfoDTO;
import com.sys.platform.entity.vo.dossierDeviceWarning.DossierDeviceWarningVO;
import com.sys.platform.service.IDossierDeviceWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 档案馆设备告警Controller
 *
 * @author yuanfuqiang
 * @date 2024-01-10
 */
@Api(tags = "档案馆设备告警管理")
@RestController
@RequestMapping("/dossierDevice/warning")
public class DossierDeviceWarningController extends BaseController {

    @Autowired
    private IDossierDeviceWarningService dossierDeviceWarningService;

    /**
     * 查询档案馆设备告警列表
     */
    @ApiOperation("查询设备告警列表")
    @GetMapping("/list")
    public TableDataInfo list(DossierDeviceWarningVO dossierDeviceWarning) {
        startPage();
        List<DossierDeviceWarningVO> list = dossierDeviceWarningService.selectDossierDeviceWarningList(dossierDeviceWarning);
        return getDataTable(list);
    }

    /**
     * 设备告警详情
     */
    @ApiOperation("设备告警详情")
    @GetMapping("/info")
    public AjaxResult info(DossierDeviceWarningInfoDTO dto) {
        DossierDeviceWarningVO deviceWarningInfo = dossierDeviceWarningService.selectDossierDeviceWarningInfo(dto);
        return AjaxResult.success(deviceWarningInfo);
    }

    /**
     * 新增档案馆设备告警
     */
    @ApiOperation("新增设备告警")
    @PostMapping
    public AjaxResult add(@RequestBody DossierDeviceWarningAddDTO dto, HttpServletRequest request) {
        DossierDeviceWarning dossierDeviceWarning = new DossierDeviceWarning();
        BeanUtil.copyProperties(dto, dossierDeviceWarning);
        dossierDeviceWarningService.insertDossierDeviceWarning(dossierDeviceWarning, request);
        return AjaxResult.success("操作成功");
    }

    /**
     * 修改档案馆设备告警
     */
    @ApiOperation("修改告警状态")
    @GetMapping
    public AjaxResult editStatus(Long id) {
        DossierDeviceWarning dossierDeviceWarning = new DossierDeviceWarning();
        dossierDeviceWarning.setId(id);
        return AjaxResult.success(dossierDeviceWarningService.updateDossierDeviceWarning(dossierDeviceWarning));
    }

    /**
     * 删除档案馆设备告警
     */
    @ApiOperation("删除设备告警")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(dossierDeviceWarningService.deleteDossierDeviceWarningByIds(ids));
    }


    /**
     * 选择告警用户列表
     */
    @ApiOperation("选择告警用户列表")
    @GetMapping("selectUser")
    public AjaxResult selectUser() {
        return AjaxResult.success(dossierDeviceWarningService.selectUserList());
    }

    /**
     * 查询告警用户列表
     */
    @ApiOperation("查询告警用户列表")
    @GetMapping("userList")
    public AjaxResult userList() {
        return AjaxResult.success(dossierDeviceWarningService.userList());
    }

    /**
     * 添加关联告警用户
     */
    @ApiOperation("添加关联告警用户")
    @GetMapping("addUser")
    public AjaxResult addUser(Long[] userId) {
        dossierDeviceWarningService.insertDossierWarningUserId(userId);
        return AjaxResult.success("操作成功");
    }

    /**
     * 删除关联告警用户
     */
    @ApiOperation("删除关联告警用户")
    @DeleteMapping("user/{ids}")
    public AjaxResult removeUserId(@PathVariable Long[] ids) {
        return AjaxResult.success(dossierDeviceWarningService.deleteDossierWarningByIds(ids));
    }
}
